package com.zzyl.service.impl;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.DeviceDataPageReqDto;
import com.zzyl.mapper.DeviceDataMapper;
import com.zzyl.mapper.DeviceDataPageMapper;
import com.zzyl.service.DeviceDataService;
import com.zzyl.vo.DeviceDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class DeviceDataServiceImpl implements DeviceDataService {

    @Autowired
    private DeviceDataPageMapper deviceDataPageMapper;

    @Override
    public PageResponse<DeviceDataVo> getpage(DeviceDataPageReqDto deviceDataPageReqDto) {
        PageHelper.startPage(deviceDataPageReqDto.getPageNum(),deviceDataPageReqDto.getPageSize());
        Long startTime = deviceDataPageReqDto.getStartTime();
        LocalDateTime startDate = LocalDateTimeUtil.of(startTime);
        deviceDataPageReqDto.setStartDate(startDate);
        Page<DeviceDataVo> deviceDataVos = deviceDataPageMapper.getpage(deviceDataPageReqDto);
        PageResponse<DeviceDataVo> deviceDataVoPageResponse = PageResponse.of(deviceDataVos, DeviceDataVo.class);
        return deviceDataVoPageResponse;
    }
}
